Completed
Push — master ( 8c53f9...1d869a )
by Marcelo
33s
created

i18n.spec.js ➔ ???   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
c 3
b 0
f 0
nc 1
dl 0
loc 32
rs 8.8571
nop 0
1
import { expect } from 'chai';
2
import { getLocale, translator } from '../src/i18n';
3
4
describe('i18n.js', () => {
5
    describe('Locale', () => {
6
        it('should get locale from machine', () => {
7
            return getLocale()
8
                .then(locale => {
9
                    expect(locale).to.match(/^[a-z]{2}_([A-Z]{2,3})?$/);
10
                });
11
        });
12
13
        it('should allow translation', () => {
14
            const zh_CN = {
15
                'I\'m 20 years old': '我是18岁'
16
            };
17
            const _ = translator(zh_CN);
18
19
            expect(_('I\'m 20 years old')).to.equals('我是18岁');
20
        });
21
22
        it('should allow string interpolation', () => {
23
            const zh_CN = {
24
                '{{name}} is {{age}} years old': '{{name}}是{{age}}岁'
25
            };
26
            const _ = translator(zh_CN);
27
            const sentence = _('{{name}} is {{age}} years old', {
28
                name: 'Celão',
29
                age: 20
30
            });
31
32
            expect(sentence).to.equals('Celão是20岁');
33
        });
34
    });
35
});
36